package com.smart4j.framework.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import lombok.extern.slf4j.Slf4j;

/**
 * 流操作工具
 *
 * @author 段誉
 * @create 2019-04-01 18:59
 */
@Slf4j
public final class StreamUtil {
  /**
   * 从输入流中获取字符串
   */
  public static String getString(InputStream is) {
    StringBuilder sb = new StringBuilder();
    try {
      BufferedReader reader = new BufferedReader(new InputStreamReader(is));
      String line;
      while ((line = reader.readLine()) != null) {
        sb.append(line);
      }
    } catch (IOException e) {
      log.error("get string failure", e);
      throw new RuntimeException(e);
    }
    return sb.toString();
  }
}
